﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathLib;

namespace TestHarness
{
    public class SimpleTestCase : TestCase
    {
        private double[] values;
        private string expected;
        public double[] Values
        {
            get { return values; }
            set { values = value; }
        }

        public string Expected
        {
            get { return expected; }
            set { expected = value; }

        }

        public override void Start()
        {
            double result = 0;
            try
            {
                switch (TestCaseName)
                {
                    case "ArithmeticMean":
                        result = Methods.ArithmeticMean(values);
                        break;

                    case "GeometricMean":
                        Methods methods = new Methods();
                        result = methods.GeometricMean(values);
                        break;

                    case "HarmonicMean":
                        result = Methods.HarmonicMean(values);
                        break;
                }

            }
            catch (Exception ex)
            {
                ConsoleColor color = Console.ForegroundColor;
                Console.Write("TestCaeID:{0},Method:{1},Inputs:{2},Expected:{3},Result:", TestCaseID, TestCaseName,ConvertToString( values), Expected);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed");
                Console.WriteLine(ex.Message);
                Console.ForegroundColor = color;
                return;
            }

            ConsoleColor orginalColor = Console.ForegroundColor;
            if (expected == result.ToString("F4"))
            {
                
                Console.Write("TestCaeID:{0},Method:{1},Inputs:{2},Expected:{3},Result:", TestCaseID, TestCaseName, ConvertToString( values), Expected);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Passed");
            }
            else
            {
                Console.Write("TestCaeID:{0},Method:{1},Inputs:{2},Expected:{3},Result:", TestCaseID, TestCaseName,ConvertToString( values), Expected);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed");
            }
            Console.ForegroundColor = orginalColor;
        }

        private string ConvertToString(double[] ds)
        {
            string str = "";
            foreach (double d in ds)
            {
                str += d.ToString()+" ";
            }

            return str;
        }
    }
}
